package com.liangliang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liangliang.pojo.CityInfo;
import com.liangliang.service.CityInfoService;
import com.liangliang.mapper.CityInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

/**
* @author 13172
* @description 针对表【city_info】的数据库操作Service实现
* @createDate 2024-07-20 21:00:55
*/
@Service
public class CityInfoServiceImpl extends ServiceImpl<CityInfoMapper, CityInfo>
    implements CityInfoService{

    @Autowired
    private CityInfoMapper cityInfoMapper;


    public void generateAndInsertData(int numberOfRecords) {
        List<CityInfo> cityInfoList = new ArrayList<>();
        Random random = new Random();
        String[] cities = {"北京", "上海", "南京", "广州", "深圳"};
        String[] areas = {"North", "South", "East", "West", "Central"};

        for (int i = 0; i < numberOfRecords; i++) {
            CityInfo cityInfo = new CityInfo();
            cityInfo.setCityId((long) (i + 1));
            cityInfo.setCityName(cities[random.nextInt(cities.length)]);
            cityInfo.setArea(areas[random.nextInt(areas.length)]);
            cityInfoList.add(cityInfo);
        }

        cityInfoMapper.insertBatch(cityInfoList);
    }

    @Override
    public List<CityInfo> findAll() {
        List<CityInfo> cityInfos = cityInfoMapper.selectAll();

        return cityInfos;
    }
}




